package com.yatuhashi.manual.mhp3.util;

import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.ImageButton;

/** ボタン押下時カラーフィルター適用クラス */
public class ButtonToucher implements OnTouchListener {
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        switch (event.getAction()) {
        case MotionEvent.ACTION_DOWN:
            ((ImageButton) v).setColorFilter(0x77000000,
                    android.graphics.PorterDuff.Mode.SRC_ATOP);
            break;
        case MotionEvent.ACTION_MOVE:
            if(event.getX() < 0 || event.getY() < 0 || event.getX() > v.getWidth() || event.getY() > v.getHeight()){
                ((ImageButton) v).clearColorFilter();
            }else {
                ((ImageButton) v).setColorFilter(0x77000000,
                        android.graphics.PorterDuff.Mode.SRC_ATOP);
            }
            break;
        case MotionEvent.ACTION_UP:
            ((ImageButton) v).clearColorFilter();
            break;
        default:
            ((ImageButton) v).clearColorFilter();
            break;
        }
        return false;
    }
}
